# @summary A short summary of the purpose of this class
#
# A description of what this class does
#
# @example
#   include clusters::defaultkernel
class clusters::defaultkernel(
Optional[String[1]] $default_kernel
) {
  #notify {"before if default_kernel is: $default_kernel":}
  if $default_kernel{

  #notify {"after if default_kernel is: ${default_kernel}":}
    $_default_kernel = "/boot/vmlinuz-${default_kernel}"
    #notify {"Default_kernel is: ${_default_kernel}":}

    package { [
        "kernel-$default_kernel",
        "kernel-devel-$default_kernel",
        "kernel-core-$default_kernel",
        "kernel-modules-$default_kernel",
        "kernel-modules-core-$default_kernel",
        "kernel-modules-extra-$default_kernel",
        "kernel-headers-$default_kernel",
      ]:
      ensure  => "installed",
      require => Yumrepo['site'],
    }->
    exec { 'set default kernel':
      command => "/sbin/grubby --set-default=${_default_kernel}",
      path    => ['/bin','/sbin'],
      unless  => "/sbin/grubby --default-kernel | grep -q ${_default_kernel}",
    }->
    exec { 'boot to default kernel':
      command => "/sbin/reboot",
      path    => ['/bin','/sbin'],
      unless  => "/bin/uname -a | grep -q ${default_kernel}",
    }
  }
}
